<?php
/*
 * 系统每隔10分钟执行的动作
 *
 */
class CCrontab
{
	/* 构造函数 */
	function __construct() {
		date_default_timezone_set('UTC');
		
		$this->OnStartCrontab();
	}
	/* 启动定时器 */
	function OnStartCrontab() {
		$this->DbgPrint("开始执行定时规则");
		$this->OpenUrl("/crontab/crontab-sendemail.php");
		$this->OpenUrl("/crontab/crontab-sendemailnotify.php");
	}
	/* 启动文件 */
	function OpenUrl($url){
		$fp = fsockopen("localhost", "80", $errno, $error);
		if( $fp ){
			fputs($fp, "GET {$url}\r\n");
			fputs($fp, "Host: localhost\r\n\r\n");
			fclose($fp);
		} else {
			$this->DbgPrint("启动{$url}失败: {$error}");
		}
		
	}
	/* 打印日志 */
	function DbgPrint($log){
		$path = dirname(__FILE__);
		$fp = fopen("{$path}/../log/crontab.log", "a");
		if( !$fp )
			return;
		fputs($fp, date("[Y-m-d H:i:s]\t"));
		fputs($fp, preg_replace("/[\r\n]/i", " ", $log) . "\r\n");
		fclose($fp);
	}
}

set_time_limit(0);
$cc = new CCrontab();
?>